var addDatabaseWin = null ;
var databaseAddPanel = null ;

Ext.BLANK_IMAGE_URL = './js/extjs/resources/images/default/s.gif';
Ext.lib.Ajax.defaultPostHeader += ";charset=utf-8"; 

//左侧操作界面
MenuPanel = function(){
	//定义模板 使用标签tpl和操作符for
	
	var datas = [  
			['pay',Application.ctx + '/js/css/menu/png36.png','收支记账','/cashflow/list.action'],  
			['out',Application.ctx + '/js/css/menu/png31.png','活期存款','/app/cashflow/cashflow.jsp'],  
			['3','./js/css/menu/png32.png','定期存款'],  
			['4','./js/css/menu/png37.png','债权'],
			['2','./js/css/menu/png31.png','活期存款1'],  
			['3','./js/css/menu/png32.png','定期存款2'],  
			['4','./js/css/menu/png37.png','债权3'] 
	] ;
	
    var tp = new Ext.XTemplate(
	   	'<tpl for=".">',
			'<div class="thumb-wrap" id={id}>',
		       '<div class="thumb"><img src={img} /></div>',
		       '<span class="x-editable">{text}</span>',
		    '</div>',
	    '</tpl>',
		'<div class="x-clear"></div>'
    );
    
	var viewDataPanel1 = new Ext.DataView({  
                 tpl: tp,  
                 singleSelect: true, 
				 overClass:'x-view-over',
            	 itemSelector:'div.thumb-wrap',
                 autoWidth:true,  
			     autoHeight:true, 
			     autoScroll: true,
			     store:new Ext.data.SimpleStore({  
				     fields:['id','img','text','url'],  
				     data:datas
				     }),
				 scope:this,
				 listeners: { 
				 	//点击
					'click':function(dataview,index,node,e){  
					    var record = dataview.getStore().getAt(index);  
					    var id = record.get('id') ;
					    var url = Application.ctx + record.get('url')
					    var _tab = mainPanel. getItem(id + 'TabDiv');
					    if ( _tab ){
					    	mainPanel.activate(id + 'TabDiv') ;
					    }else{
					    	_tab = mainPanel.add({
						    		id:id + 'TabDiv' ,
						    		title:record.get('text'),
						    		closable: true,
						    		layout:'fit'
					    		});
					    	_tab.show();
					    	_tab.load({
								    url: url, 
								    params: {param1: "foo", param2: "bar"}, // or a URL encoded string
								    //callback: yourFunction,
								    scope: this , // optional scope for the callback
								    discardUrl: false,
								    nocache: false,
								    text: "Loading...",
								    timeout: 30,
								    scripts: true
							});
							
					    	mainPanel.activate(id + 'TabDiv') ;
					    }
					} 
            	}

             });  

	MenuPanel.superclass.constructor.call( this , {
		id:'menu',
		region:'west',
        split:true,
        width: 190,
        minSize: 190,
        maxSize: 500,
        collapsible: true,
        layout:'accordion',
        margins:'0 0 5 5',
        cmargins:'0 0 0 0',
        items:[
        	new Ext.Panel({
                title: '理财管理',
                id:'images-view',
                frame:true,
                items:[
                	viewDataPanel1
                ]
            }),
            new Ext.Panel({
                title: '个人理财',
                frame:true,
                html: '&lt;empty panel&gt;',
                cls:'empty'
            }),
            new Ext.Panel({
                title: '报表中心',
                frame:true,
                html: '&lt;empty panel&gt;',
                cls:'empty'
            }),
            new Ext.Panel({
                title: '系统维护',
                frame:true,
                html: '&lt;empty panel&gt;',
                cls:'empty'
            })
        ]
	});
}
Ext.extend(MenuPanel , Ext.Panel);

MainPanel = function(){
	MainPanel.superclass.constructor.call(this, {
		id:'MainPanel',
		region:'center',
        margins:'0 5 5 0',
        resizeTabs: true,
        minTabWidth: 135,
        tabWidth: 135,
        activeTab: 0,
        items:[
        	{title:'欢迎使用本系统' ,  autoLoad:'welcome.htm'}
        ]
	});
};
Ext.extend(MainPanel , Ext.TabPanel );

HeadPanel = function(){
	
	HeadPanel.superclass.constructor.call(this , {
		border: false,
        layout:'anchor',
        region:'north',
        cls: 'docs-header',
        height:60,
        items:[
        {
            xtype:'box',
            el:'header',
            border:false,
            anchor: 'none -25'
        },new Ext.Toolbar({
            cls:'top-toolbar',
            items:['-',
            new Ext.form.Label({
				el:'UserInfo'
			}),'-',
			new Ext.form.Label({
				el:'DepartInfo'
			}),'-', 
			{	
				iconCls: 'user_button',
				tooltip: '用户信息'
            },' ', '->','-',
			{	
				iconCls: 'help_button',
				tooltip: '帮助',
				enableToggle: true,
                handler: function(){ alert('test'); }
            },'-'
            ]
        })
        ]
	});
};
Ext.extend(HeadPanel , Ext.Panel );

var mainPanel = new MainPanel();
var headPanel = new HeadPanel();
var menuPanel = new MenuPanel();	

Ext.onReady(function(){
	Ext.QuickTips.init();
	Ext.form.Field.prototype.msgTarget = 'side';
	
	var viewport = new Ext.Viewport({
        layout:'border',
        items:[ headPanel, menuPanel , mainPanel ]
    });
   
	
	
    
    viewport.doLayout();
});